/*
* 优惠券使用记录
* @Author: Li Yujie
* @Date: 2020-11-14
*/
<template>
    <div class="wrapper">
        <!--筛选表单-->
        <div class="filter-view">
            <el-input
                class="input-with-select"
                placeholder="请输入用户昵称/手机号/订单编号"
                v-model="filterData.keyword"
                suffix-icon="el-icon-search"
                size="medium"
                clearable
                @blur="getTableData(1)"
                @keydown.enter.native="getTableData(1)"
            />
        </div>
        <!--/筛选表单-->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            ref="tempLateName"
        >
            <el-table-column
                type="index"
                label="序号"
                align="center"
                width="80"
            />
            <el-table-column
                prop="true_name"
                label="使用人昵称"
                show-overflow-tooltip
                align="left"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="phone"
                label="使用人手机号"
                show-overflow-tooltip
                align="center"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="school_name"
                label="学校名称"
                show-overflow-tooltip
                align="left"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop=""
                label="使用时间"
                show-overflow-tooltip
                align="center"
            >
                <template slot-scope="scope">
                    {{ scope.row.use_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="order_no"
                label="订单号"
                align="center"
                width="240"
            />
            <el-table-column
                prop=""
                label="实付金额"
                align="center"
            >
                <template slot-scope="scope">
                    <div>￥{{ scope.row.actual_money }}</div>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- 分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                layout="total, prev, pager, next, jumper"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>
    </div>
</template>

<script>
export default {
    name: "UseRecord",
    props: {
        couponNo: {
            type: String,
            required: true
        },
    },
    data() {
        return {
            filterData: {
                filterType: '1',
                keyword: ''
            },
            tableData: [],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
        };
    },
    mounted() {
        this.getTableData();
    },
    methods: {

        /**
         * 获取表格数据
         * @param page
         */
        getTableData(page) {
            let params = {...this.filterData};

            params.coupon_no = this.couponNo;
            params.page_id = page || this.page.now_page;
            this.$post('/student/shop_goods_coupon%5Cget_use_list', params, resp => {
                if (resp.code === 1) {
                    this.tableData = resp.data.list;
                    this.page = resp.data.page;
                } else {
                    this.$notify({
                        title: '失败',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });

        },
        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },
    }
};
</script>

<style scoped lang="less">
.wrapper {
    display: flex;
    height: calc(100% - 24px);
    width: calc(100% - 48px);
    flex-direction: column;
    position: relative;
    margin: 0 24px 24px;
    background: #fff;
    box-sizing: border-box;

    /*筛选*/
    .filter-view {
        margin: 6px 0 24px;
        display: flex;
        justify-content: space-between;
        .input-with-select {
            width: 372px;
            margin-right: 32px;
        }

        /deep/ .input-with-select .el-input-group__prepend {
            background-color: #fff;
            width: 130px;
        }
    }

    /* 分页 */
    .pagination-wrapper {
        padding: 10px 32px;

        .el-pagination {
            float: right;
            padding: 0;
            background-color: transparent;
        }
    }
}
</style>
